package com.zxy.ziems.server.budget.convertor;

import com.zxy.ziems.server.budget.pojo.dto.BudgetValDTO;
import com.zxy.ziems.server.budget.pojo.entity.BudgetValueEntity;
import com.zxy.ziems.server.budget.pojo.vo.BudgetValueVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface BudgetValueConvertor {
    BudgetValueConvertor INSTANT = Mappers.getMapper(BudgetValueConvertor.class);

    List<BudgetValueVO> EntityList2VoList(List<BudgetValueEntity> budgetValueEntities);

    @Mapping(target = "budgetMonth", expression = "java(Integer.valueOf(budgetValDTO.getBudgetMonth()))")
    BudgetValueEntity dto2Entity(BudgetValDTO budgetValDTO);

    default List<BudgetValueEntity> dtoList2EntityList(List<BudgetValDTO> budgetValDTOList) {
        return budgetValDTOList.stream().map(this::dto2Entity).collect(Collectors.toList());
    }
}
